/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { Space, Popconfirm } from 'antd';
import type { CloudCallSwitch } from '../../../../index.d';

interface STATUS {
  status: string;
  tips: string;
  optionText: string;
}

interface SwitchType {
  open: STATUS;
  close: STATUS;
}

const KbSwitch = ({ status, record, onSwitch }: CloudCallSwitch) => {
  const switchType: SwitchType = {
    close: {
      status: '已关闭',
      tips: '是否开启白名单？',
      optionText: '开启',
    },
    open: {
      status: '已开启',
      tips: '是否关闭白名单?',
      optionText: '关闭',
    },
  };

  const handleSwitch = () => {
    const { only_sms_auth } = record;
    const type = only_sms_auth == 1 ? 0 : 1;
    onSwitch(type);
  };

  const switchStatus = status == 0 ? 'close' : 'open';
  return (
    <Space direction='vertical'>
      <span>{switchType[switchStatus].status}</span>
      <Popconfirm
        title={`${switchType[switchStatus].tips}`}
        onConfirm={handleSwitch.bind(null, {})}
      >
        <a>{switchType[switchStatus].optionText}</a>
      </Popconfirm>
    </Space>
  );
};

export default KbSwitch;
